<template>
  <div class="w-240px h-292px rounded-4px relative">
    <advertise
      background="linear-gradient(146.46deg, #B3EFFC 0%, #56B2C7 99.25%)"
      line-color="#23A2BF"
      title="新款推荐"
      description="发现好货"
      enter="立即进入"
      img="http://127.0.0.1:7001/public/static/pentakill.jpg"
      @on-enter="enterRecommend"
    >
      <n-carousel autoplay :interval="2000" style="width: 212px; height: 156px; margin-top: 14px">
        <img
          v-for="newProduct in newProducts"
          :key="newProduct.id"
          class="w-212px h-156px cursor-pointer rounded-4px"
          :src="newProduct.imgUrl"
          alt=""
          @click="godetail(newProduct)"
        />
      </n-carousel>
    </advertise>
  </div>
</template>

<script setup lang="ts">
import useHttp from '@renderer/utils/http'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const newProducts = ref<any>([])
const godetail = (spu) => {
  router.push({ name: 'Detail', params: { id: spu.id } })
}
onMounted(async () => {
  const { data: res } = await useHttp('/new/c/list').get().json()
  if (res.value.code === 200) {
    newProducts.value = res.value.data.map((r) => {
      const { imgs } = r
      if (imgs) {
        r.imgUrl = JSON.parse(imgs)?.[0]?.url
      }
      return r
    })
  }
})
const enterRecommend = () => {
  console.log(123)
}
</script>

<style scoped></style>
